<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title></title>
    [#include "/admin/include/admin_static.htm"]
    <script type="text/javascript">


        $(function () {
            layui.use(['form', 'layer','upload','layedit'], function () {
                var form = layui.form(), $ = layui.jquery, layer = layui.layer,upload = layui.upload,layedit = layui.layedit;

                form.on('switch(switch)', function(data){

                    if(data.elem.checked){
                        $('#nd_time').show();
                        $('#auto_status').val(1);

                    }else{
                        $('#nd_time').hide();
                        $('#auto_status').val(0);
                    }
                });
                layui.upload({
                    url: '/system/upload/submit.aspx'
                    ,success: function(res){
                        if (res["error"] == 0) {
                            $("#borrowImgs").append('<img alt="" src="'+res["url"]+'" width="90px" height="90px">').append( "<input type='checkbox' name='borrowImgs' value="+res["url"]+" lay-skin='primary' checked>");
                        } else {
                            layui.alert(res["message"]);
                        }
                    }
                });
                form.on('submit(saveForm)', function (data) {
                    //图片
                    var chk_value =[];
                    $('input[name="borrowImgs"]:checked').each(function(){
                        chk_value.push($(this).val());
                    });
                    data.field.borrowImgs = chk_value;

                    var index = layer.load();
                    ajax({
                        url: "${path}/admin/borrow/save.aspx",
                        data: data.field,
                        success: function (result) {
                            layer.msg(result.content,{time:200}, function () {
                                location.reload();
                            });
                            layer.close(index);
                        },
                        complete: function () {
                            layer.close(index);
                        }
                    });
                    return false;
                });


                form.on('submit(publishForm)', function (data) {
                    //图片
                    var chk_value =[];
                    $('input[name="borrowImgs"]:checked').each(function(){
                        chk_value.push($(this).val());
                    });
                    data.field.borrowImgs = chk_value;
                    var index = layer.load();
                    ajax({
                        url: "${path}/admin/borrow/publish.aspx",
                        data: data.field,
                        success: function (result) {
                            layer.msg(result.content, {time:2000},function () {
                                location.href="${path}/admin/borrow/borrowList.aspx?status=0";
                            });
                            layer.close(index);
                        },
                        complete: function () {
                            layer.close(index);
                        }

                    });
                    return false;
                });
            });
        });
    </script>
</head>
<body>
<div class="main_admin_content">

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>融资申请</legend>
    </fieldset>



    <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">项目名称：</label>
                <div class="layui-input-block">
                    <input name="name" id="name" type="text" class="layui-input"  value="${borrow.name }" placeholder="请输入项目名称"/>
                </div>
            </div>
        <div class="layui-form-item">
            <label class="layui-form-label">自动发布</label>
            <div class="layui-input-block">
                <input name="auto_status" id="auto_status" value="0" style="display: none">
                <input type="checkbox" name="isagree" lay-skin="switch" lay-text="开启|关闭" lay-filter="switch"  value="1"  >
            </div>
        </div>

            <div class="layui-form-item "id="nd_time" style="display: none">
                <label class="layui-form-label">预定发布时间:</label>
                <div class="layui-inline">
                <input name="nd_verify_time" id="nd_verify_time" onclick="WdatePicker();" type="text" class="layui-input   value="${borrow.nd_verify_time }" placeholder="请输入拟发布时间"/>
            </div>
            </div>




            <div class="layui-form-item">
                <div class="layui-inline">
                <label class="layui-form-label">项目类型：</label>
                <div class="layui-input-block">
                    [@u.select_map headerKey="" headerValue="全部类型"
                    listKey="id" listValue="category_name"
                    headerButtom="false" list=borrowTypes
                    name="type"  value=borrow.loan_category/]
                </div>
                    </div>

        <div class="layui-inline">

                <label class="layui-form-label">项目金额</label>
                <div class="layui-input-block">
                <input type="text" id="account" class="layui-input" name="account" required="required" placeholder="请输入项目金额" value="${borrow.account }" onkeyup="value=value.replace(/[^\d.]/g,'')" />
                </div>


        </div>
            </div>
             <div class="layui-form-item">
                 <label class="layui-form-label">年化收益(单位:%)：</label>
                 <div class="layui-input-block">
                     <input type="text" value="${borrow.apr }" id="apr" class="layui-input"
                           name="apr" class="ba" onkeyup="value=value.replace(/[^\d.]/g,'')" />
                 </div>
            </div>
        <div class="layui-form-item">
            <label class="layui-form-label">融资期限</label>
            <div class="layui-input-block">
                <div class="layui-inline">
                    <input type="text" id="time_limit" class="layui-input"
                           value="${borrow.time_limit }" name="time_limit"/>
                </div>
                <div class="layui-inline">
                    [@u.radio  name="is_day" list={'0': '月', '1':'天'}  class="layui-radio" value=borrow.is_day /]
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">支持体验红包</label>
            <div class="layui-input-block">
                <div class="layui-inline">
                [@u.radio  name="red_packet_status" list={'0': '否', '1':'是'}  class="layui-radio" value=borrow.red_packet_status /]
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">还款方式</label>
            <div class="layui-input-block">
                    <select id="style" name="style">
                    [#if borrow.is_day==1 ] disabled="disabled" [/#if]
                    [@p2p_dict nid="borrow_style"]
                    [#list  dictList as borrow_style]
                        <option [#if borrow.pay_style==borrow_style.dict_value ] selected="selected" [/#if] value='${borrow_style.dict_value}'>
                        ${borrow_style.dict_lab}
                        </option>
                    [/#list]
                    [/@p2p_dict]
                    </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">投标限额(单位/元)：</label>
            <div class="layui-inline">

               <input type="text" value="${borrow.min_account }" class="layui-input"
                           id="min_account" name="min_account" placeholder="请输入最低投标限额"
                           onkeyup="value=value.replace(/[^\d.]/g,'')" />
           </div>
            <div class="layui-inline">

                <input type="text" value="${borrow.max_account}" class="layui-input" placeholder="请输入最高投标限额"
                           id="max_account" name="max_account"
                           onkeyup="value=value.replace(/[^\d.]/g,'')" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">筹款时间:</label>
            <div class="layui-input-block">
                    <input type="text" value="${borrow.valid_time }"
                           id="valid_time" name="valid_time" placeholder="请输入筹集时间" class="layui-input"
                           onkeyup="value=value.replace(/[^\d.]/g,'')" />

                </div>
        </div>
        [#--<div class="layui-form-item">--]
            [#--<label class="layui-form-label">项目密码:</label>--]
            [#--<div class="layui-input-block">--]
                [#--<input type="text" value="${borrow.tbpwd}"--]
                               [#--id="tbpwd" name="tbpwd" class="layui-input"--]
                                  [#--onkeyup="value=value.replace(/[^\d.]/g,'')" /> </div>--]
        [#--</div>--]
        <div class="layui-form-item">
            <label class="layui-form-label">百分比奖励:</label>
            <div class="layui-input-block">
                <input type="text" value="${borrow.radio_account!'0' }" id="radio_account"  class="layui-input"
                               name="radio_account" onkeyup="value=value.replace(/[^\d.]/g,'')" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">借款用途:</label>
            <div class="layui-input-block">
              <textarea rows="10" cols="30" id="use" name="use" class="layui-textarea"> ${borrow.use }</textarea>

            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">项目描述:</label>
            <div class="layui-input-block">
                <textarea name="content" id="content" cols="30" rows="10" class="layui-textarea">${borrow.content }</textarea>
            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">合同照片:</label>
            <div class="layui-input-block"><input type="file"  name="file"  class="layui-upload-file"/></div>

        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">照片:</label>
            <div id="borrowImgs" class="layui-input-block">
            [#list  borrowImgs as img]
                <a href="${img.img}" target="_blank">
                    <img alt="" src="${img.img}" width="90px" height="90px" />
                </a>
                <input type="checkbox" name="borrowImgs" value="${img.img}" checked="checked" />
            [/#list]
            </div>
        </div>

        <div class="layui-form-item">
                    <td colspan="100" class="btn_td">
                        <input name="borrowId" type="hidden" value="${borrow.id }" />
                        [#if  (borrow.status < 4 && borrow.status >0)||borrow.status==0 ]
                        <div class="layui-input-block">
                        <div class="layui-inline">
                            <button lay-submit lay-filter="saveForm" class="layui-btn" style="width: 280px;margin-top:3px;">暂存</button>
                            </div>
                        <div class="layui-inline">
                            <button lay-submit lay-filter="publishForm" class="layui-btn" style="width: 280px;margin-top:3px;">确认借款</button>
                            </div>
                            </div>
                        [/#if]

                    </td>
        </div>

    </form>
</div>
<script type="text/javascript">


    //项目介绍
    KindEditor
            .ready(function(K) {
                var editor1 = K
                        .create(
                                'textarea[name="content"]',
                                {
                                    cssPath : '${path}/resources/plug/kindeditor/plugins/code/prettify.css',
                                    uploadJson : '${path}/system/upload/submit.aspx',
                                    fileManagerJson : '${path}/resources/plug/kindeditor/jsp/file_manager_json.jsp',
                                    allowFileManager : true,
                                    afterCreate : function() {
                                        var self = this;
                                        K.ctrl(document, 13, function() {
                                            self.sync();
                                            document.forms['example']
                                                    .submit();
                                        });
                                        K
                                                .ctrl(
                                                        self.edit.doc,
                                                        13,
                                                        function() {
                                                            self.sync();
                                                            document.forms['example']
                                                                    .submit();
                                                        });
                                    },
                                    afterBlur : function() {
                                        this.sync();
                                    }
                                });
                prettyPrint();
            });
</script>
</body>
</html>